import request from "@/utils/request";
import type { OrderDetailVO, OrderInfoVO, OrderItemVO, OrderStatusDTO, SubmitOrderDTO, WxPaymentParamsDTO } from "@/types/orderType";
import type { Page } from "@/types/response";
import type { CartItemVO } from "@/types/cartType";

enum ENUM {
   fetchOrderListAPI = "/member/order",
   deleteOrderAPI = "/member/order",
   cancelOrderAPI = "/member/order",
   receiveAPI = "/member/order",
   sendAPI = "/member/order/consignment",
   fetchOrderInfoAPI = "/member/order/pre",
   fetchOrderNowInfoAPI = "/member/order/pre/now",
   submitOrderAPI = "/member/order",
   findOrderDetailAPI = "/member/order",
   fetchOrderLogisticsAPI = "/member/order",
   mockPaymentAPI = "/pay/mock",
   findWxPaymentParamsAPI = "/pay/wxPay/miniPay"
}

/**
 * @description 获取订单列表的接口
 * */
export const fetchOrderListAPI = (data: OrderStatusDTO) => request<Page<OrderItemVO[]>>({
   method: "GET",
   url: ENUM.fetchOrderListAPI,
   data,
});

/**
 * @description 删除订单的接口
 * */
export const deleteOrderAPI = (ids: string[]) => request<void>({
   url: ENUM.deleteOrderAPI,
   method: "DELETE",
   data: {
      ids,
   },
});

/**
 * @description 取消订单的接口
 * */
export const cancelOrderAPI = (id: string, data: { cancelReason: string }) => request<CartItemVO>({
   url: `${ENUM.cancelOrderAPI}/${id}/cancel`,
   method: "PUT",
   data,
});

/**
 * @description 确认收货接口
 * */
export const receiveAPI = (id: string) => request({
   url: `${ENUM.receiveAPI}/${id}/receipt`,
   method: "PUT",
});

/**
 * @description 模拟发货的接口
 * */
export const sendAPI = (id: string) => request<void>({
   url: `${ENUM.sendAPI}/${id}`,
   method: "GET",
});

/**
 * @description 获取预付订单信息的接口
 * */
export const fetchOrderInfoAPI = () => request<OrderInfoVO>({
   url: ENUM.fetchOrderInfoAPI,
   method: "GET",
});


/**
 * @description 获取立即购买订单信息的接口
 * */
export const fetchOrderNowInfoAPI = (data: { skuId?: string, count?: number, addressId?: string }) => request<OrderInfoVO>({
   url: ENUM.fetchOrderNowInfoAPI,
   method: "GET",
});


/**
 * @description 提交订单的接口
 * */
export const submitOrderAPI = (data: SubmitOrderDTO) => request<{ id: string }>({
   url: ENUM.submitOrderAPI,
   method: "POST",
   data,
});


/**
 * @description 获取订单详情的接口
 * */
export const findOrderDetailAPI = (id: string) => request<OrderDetailVO>({
   url: `${ENUM.findOrderDetailAPI}/${id}`,
   method: "GET",
});

/**
 * @description 获取订单物流的接口
 * */
export const fetchOrderLogisticsAPI = (id: string) => request({
   url: `${ENUM.fetchOrderLogisticsAPI}/${id}/logistics`,
   method: "GET",
});

/**
 * @description 模拟支付的接口
 * */
export const mockPaymentAPI = (id: string) => request<void>({
   url: `${ENUM.mockPaymentAPI}`,
   method: "GET",
   data: {
      orderId: id,
   },
});

/**
 * @description 获取微信支付参数的接口
 * */
export const findWxPaymentParamsAPI = (id: string) => request<WxPaymentParamsDTO>({
   url: ENUM.findWxPaymentParamsAPI,
   method: "GET",
   data: {
      orderId: id,
   },
});